package com.along.utility.common.response;

/**
 * @Author liujinyi
 * @Date 2024/12/24 17:49
**/
public class GeneralResult<T> {
	private T data;
	private Integer code;
	private String msg;

	public static <T> GeneralResult<T> success() {
		return new GeneralResult<T>(DefaultResultCode.SUCCESS, null);
	}

	public static <T> GeneralResult<T> success(T data) {
		return new GeneralResult<T>(DefaultResultCode.SUCCESS, data);
	}

	public static <T> GeneralResult<T> of(ResultCode resultCode, T data) {
		return new GeneralResult<T>(resultCode, data);
	}

	public static <T> GeneralResult<T> of(ResultCode resultCode) {
		return new GeneralResult<T>(resultCode, null);
	}

	private GeneralResult(ResultCode resultCode, T data) {
		this.code = resultCode.getValue();
		this.msg = resultCode.getMessage();
		this.data = data;
	}

	public GeneralResult(){}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

}
